<?php
namespace Common\Model;
use Think\Model;
use Think\Upload;

/**
 * 文章 模型
 */
class DianpuModel extends Model {
	public static $mystat = array('del'=>'-1','forbid'=>'0','allow'=>'1');
	public static $ablemap = array('status'=>'1'); //状态正常的查询条件

	protected $_auto = array(
			array('updatetime',NOW_TIME,self::MODEL_BOTH)
	);

	/**
	 * 绑定店铺
	 */
	public function myBangding($data) {
		//先create验证数据
		if (false ===$this->create($data,self::MODEL_UPDATE)) return false;
	
		//身份证正面
		if (!empty($data['shouye'])) {
			$setting = C('PICTURE_UPLOAD');
			$Upload = new Upload($setting);
			$image = $Upload->uploadOne($data['shouye']);
			if (!$image) {
				$this->error = $Upload->getError();
				return false;
			}
			$image['path'] = $setting['rootPath'].$image['savepath'].$image['savename']; //在模板里的url路径
			$this->shouye = $image['path'];
		}else {
			unset($this->shouye);
		}//身份证背面
		if (!empty($data['houtai'])) {
			$setting = C('PICTURE_UPLOAD');
			$Upload = new Upload($setting);
			$image = $Upload->uploadOne($data['houtai']);
			if (!$image) {
				$this->error = $Upload->getError();
				return false;
			}
			$image['path'] = $setting['rootPath'].$image['savepath'].$image['savename']; //在模板里的url路径
			$this->houtai = $image['path'];
		}else {
			unset($this->houtai);
		}
	
		return $this->add();
	}	
}
